﻿// Options.cs
// This program contains a class that holds the Command Line Arguments and helps process them

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommandLine.Text;
using CommandLine;

namespace armsim
{

    /// <summary>
    /// Processes and stores the command line options for the arm simulator
    /// </summary>
    public class Options
    {

        /// <summary>
        /// Checks to see if the Options is in a valid state.
        /// </summary>
        /// <returns>True if in a valid state. Otherwise, false</returns>
        public Boolean CheckState()
        {

            if (this.TestFlag == true)
            {
                return true;
            }

            if (this.InputFile == null)
            {
                return false;
            }

            if (this.MemorySize > 1048576U)
            {
                Logger.LogEvent("Error: Arm Simulator only supports up to 1 MB of memory.");
                return false;
            }

            return true;

        }

        /// <summary>
        /// Contains the file to be loaded into ram
        /// </summary>
        [Option(null, "load", HelpText = "The file to be loaded.")]
        public String InputFile { get; set; }

        /// <summary>
        /// Contains the number of bytes that the ram should have
        /// </summary>
        [Option(null, "mem", HelpText = "The memory size.", DefaultValue = 32768U)]
        public uint MemorySize { get; set; }

        /// <summary>
        /// Flag indicating whether unit tests should be run or not
        /// </summary>
        [Option(null, "test", HelpText = "The test flag.", DefaultValue = false)]
        public Boolean TestFlag { get; set; }

        /// <summary>
        /// Flag indicating whether to run the loaded file or not. Ignored if --load command absent
        /// </summary>
        [Option(null, "exec", HelpText = "Execute loaded file")]
        public Boolean Exec { get; set; }

        /// <summary>
        /// Gets the error screeen
        /// </summary>
        /// <returns>String containing an error message</returns>
        [HelpOption(HelpText = "Dispaly this help screen.")]
        public string GetUsage()
        {
            return "armsim [ --load elf-file ] [ --mem memory-size ] [ --test]";
        }
    }
}
